package com.yeci.utils;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @description: 自定义MyBatisPlus自动填充类
 * @author: yeci
 * @date: 2021/8/1 20:27
 **/
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
  @Override
  public void insertFill(MetaObject metaObject) {
    log.info("start insert fill......");
    // setUpdateFieldValByName(String fieldName, Object fieldVal, MetaObject metaObject)
    this.setFieldValByName("createTime",new Date(),metaObject);
    this.setFieldValByName("updateTime",new Date(),metaObject);
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    log.info("start update fill......");
    this.setFieldValByName("updateTime",new Date(),metaObject);
  }
}
